//page gui
function  mm()
{
	
	
}
function get_post_callback(data)
{
	 //alert(data);
	data=str2json(data);
	
	try{
	$("#thumb").attr("src","../z/"+data.thumb);}catch(e){}
	
	try{
		$("#img").css("background-image","url(../z/"+data.thumb+")");	
		//$("#img").css("background","../z/"+data.thumb);	
		$("#img2").attr("src","../z/"+data.thumb);	
		//alert($("#img").css("background-image"));
	}catch(e)
	{
 		showErr(e);	
	}
	$("#material_description").text(data.material_description);
	
	
}

function cloneArr(rows)
{
	var s=JSON.stringify(rows) ;
	return JSON.parse(s);
 
}
function fmtPicPath(rows)
{
		var len=getJsonLength(rows);
	for(var cur=0;cur<len;cur++)	 
	{
		var item=rows[cur];
		var urlencode=encodeURIComponent("z:/"+item.img);
		item.thumb="PicReadServlet?src="+urlencode;
		item.img="PicReadServlet?src="+urlencode;
		
	}
}
function onSelectPageQB(new_pageNumber, pageSize)
{
 //	 alert("new page num:"+new_pageNumber);
 
	 //get cate  if no set
	// get_posts(null,get_posts_callback);
	var temp=function(data12){
		var data=cloneArr(testarr);
		//testarr.concat(); 
		
		data=data.slice((new_pageNumber-1)*pageSize  ,  pageSize*new_pageNumber);
		
	 	get_posts_callback(data);
	}
	temp(1);
	
}
// append to list
function get_posts_callback(data)
{
	
	console.log(data);
	fmtPicPath(data);
//	console.log("onSelectPageQB ::img: "+testarr[0].img);
//	alert(testarr[0].img);
	console.log("--fmted:"+data);
 //alert(data);
//	data=str2json(data);
	try{	
		// arr=data;
		// gotoPageEvent(1);
//		alert($('#list_ui'));
		/*
		  $scope.$apply(function() {
    $scope.time = new Date();
  });   
  */
  
   　list_scope.$apply(function () {
			var len=getJsonLength(data);
			for(var cur=0;cur<len;cur++)	 
			{
					var item=data[cur];
					list_scope.datas.push(item);
			}		
      　　
			window.setTimeout(function(){
				 checkCanSeeNextBtn();
				},1000);
	        
       });
	   
	   
		//  $('#list_ui').scope().datas =data;
		//   $('#list_ui').scope().$digest();
		// alert(arr);
	  
	  }catch(e)
	{
		showErr(e);	
	}
}

function bindPa(li){
	
	try{
		　$("#table1_tmpl").tmpl(li).appendTo('#table1');
	//	alert("ok");
	}catch(e){  showErr(e);
	}
	};

function menu_click2(cate)
{
	 $("#doc-oc-demo2").offCanvas('close');
	  $("#wrapper").css("margin-top","0px");
 get_posts({"cate":cate});	

}

function clr_list_area()
{
$("#table1").html("");	
 

}

function page_load()
{
/*var o={	pagesize:3,keyword:"",rows:arr,bind_handler:bindPa};
	//page gui
	//alert(listPaf2);
	 listPaf2(o);*/
	 try{
		 
	
	// next_click();
	// next_click();
		 
//	$("#table1_tmpl").hide();	
	
	iniMenuEvent();
	
	
	 }catch(e)
	 {
		showErr(e); 
	 }
}

function iniMenuEvent()
{
$("#left_menu_div span").each(function(index, element) {
    $(element).click(function(){
		var cate=$(this).text();
		menu_click2(cate);
		
	});
	
});
	
}

$.fn.isOnScreen = function(){
     
    var win = $(window);
     
    var viewport = {
        top : win.scrollTop(),
        left : win.scrollLeft()
    };
    viewport.right = viewport.left + win.width();
    viewport.bottom = viewport.top + win.height();
     
    var bounds = this.offset();
    bounds.right = bounds.left + this.outerWidth();
    bounds.bottom = bounds.top + this.outerHeight();
     
    return (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom));
     
};

var ListCtrlVar33=function ($scope) { 

    $scope.datas = [ 

        {"img":" image_01.png", "post_title":"url 01 description"}, 

        {"img":" image_02.png", "post_title":"url 02 description"} 

       

    ]; 

}
var list_scope;
var app = angular.module('MyApp', []);
app.controller('ListCtrlVar',function($scope){
	list_scope=$scope;
     $scope.msg = 'hello';
	  $scope.datas = [ 

      

       

    ]; 
})
function ListCtrlVar2($scope) { 

    $scope.datas = [ 

        {"img":" image_01.png", "post_title":"url 01 description"}, 

        {"img":" image_02.png", "post_title":"url 02 description"} 

       

    ]; 

} 
/*
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.firstName = "John";
    $scope.lastName = "Doe";
	 $scope.datas = [ 

        {"img":" image_01.png", "post_title":"url 01 description"}, 

        {"img":" image_02.png", "post_title":"url 02 description"} 

       

    ]; 
});
*/
var pageCtrl;
 function nextBtn_click()
 {
	 pageCtrl.next_click();
 }
 function checkCanSeeNextBtn()
 {
	 var rzt=$("#scrool_spy").isOnScreen();
	//rzt=false;
	console.log( "visible spy::"+rzt);		
	if(rzt)
	{
		
		
			console.log("--will next click evtn");
			
			pageCtrl.next_click();
			
	}
	 
	 
 }
$(function() {
		pageCtrl=new paggingGui();
			pageCtrl.onSelectPage=onSelectPageQB
			 setPageSpy();
//	menu_click2("爱情类");
	checkCanSeeNextBtn();
	
	/*	
window.setInterval(function(){
	
	},500);*/

	});